package application;


import commands.AbstractCommand;

/**
 * This class runtime execute Classes and call method help();
 * @author Josef Vopalecky
 *
 */
public class HelpBox extends Application{
	String name;
	int id;
	Core core;
	
	/**
	 * Constructor set default values.
	 * @param name
	 * @param core
	 */
	public HelpBox(String name, Core core){
		this.name = name;
		this.core = core;
	}

	/**
	 * Set process ID.
	 * @param id
	 */
	public void setId(int id){
		this.id = id;
	}
	
	/**
	 * Dynamically calls the help.
	 */
	@Override
	public void code() {
		AbstractCommand ac;
		try {
			if(name.length() > 0){
				name = Character.toUpperCase(name.charAt(0)) + name.substring(1);
				ac = (AbstractCommand) Class.forName("commands." + name).newInstance();
				core.getGui().writeConsole(ac.help());
			}
			else{
				core.getGui().writeConsole("Wrong name.\n");
			}
		
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			core.getGui().writeConsole("InstantionException.\n");
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			core.getGui().writeConsole("IllegalAccessException.\n");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			core.getGui().writeConsole("ClassNotFoundException. Try command Man.\n");
		}
		catch (NoClassDefFoundError e){
			core.getGui().writeConsole("NoClassDefFoundError. Try command Man.\n");
		}
		core.closeOut(id);
		core.cleanLastProccess();
		
	}
	

}
